<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="test"></div>

    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
        // 1.创建组件
        class Weather extends React.Component {
            // 构造器
            constructor(props) {
                super(props)
                // 初始状态
                this.state = { isHot: false }
                this.dom1 = this.dom.bind(this)
            }
            render(h) {
                //读取状态
                const { isHot } = this.state
                return <h1 onClick={this.dom1}>今天天气很{isHot ? "炎热" : "凉爽"}</h1>
            }
            dom() {
                // 严重注意：状态必须通过setState进行更新
                let { isHot } = this.state
                this.setState({ isHot: !isHot })


                //严重注意：状态不可直接更改,下面这行就是直接更改
                // this.state.isHot = !this.state.isHot
            }
        }

        ReactDOM.render(<Weather />, document.getElementById('test'))


    </script>
</body>

</html>